﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zad2
{
    public static class Extensions
    {
        public static decimal SumOfElements<T>(this IEnumerable<T> collection)
        {
            decimal sum = 0;
            foreach (var item in collection)
            {
                sum += Convert.ToDecimal(item);
            }
            return sum;
        }

        public static decimal ProductOfElements<T>(this IEnumerable<T> collection)
        {
            decimal product = 1;
            foreach (var item in collection)
            {
                product *= Convert.ToDecimal(item);
            }
            return product;
        }

        public static T MinValue<T>(this IEnumerable<T> collection)
            where T : IComparable<T>
        {
            T minValue = collection.First();
            foreach (var item in collection)
            {
                if (minValue.CompareTo(item) > 0)
                {
                    minValue = item;
                }
            }
            return minValue;
        }

        public static T MaxValue<T>(this IEnumerable<T> collection) 
            where T : IComparable<T>
        {
            T maxValue = collection.First();
            foreach (var item in collection)
            {
                if (maxValue.CompareTo(item) < 0)
                {
                    maxValue = item;
                }
            }
            return maxValue;
        }

        public static decimal AverageOfElements<T>(this IEnumerable<T> collection)
        {
            decimal sum = 0;
            int count = 0;
            foreach (var item in collection)
            {
                sum += Convert.ToDecimal(item);
                count++;
            }
            return sum / count;
        }
    }
    class Program
    {
        static void Main()
        {
            int[] a = { 5, 7, 6, 1, 8 };
            //string[] a = { "adwd", "ghgjhj", "lhdb"};
            Console.WriteLine(a.Average());
        }
    }
}
